//引入Vue核心库
import Vue from 'vue'
//引入Vuex
import Vuex from 'vuex'
//应用Vuex插件
Vue.use(Vuex)

const tab = {
    state: {
        isCollapse: false,
        tabsList: [
            {
                path: '/',
                name: 'home',
                title: '首页',
                icon: 'home'
            }
        ],
        currentMenu: null
    },

    mutations: {
        collapseMenu(state) {
            state.isCollapse = !state.isCollapse
        },
        selectMenu(state, val) {
            if (val.title !== 'home') {
                state.currentMenu = val;
                const result = state.tabsList.findIndex(item => item.title === val.title);
                if (result === -1) {
                    state.tabsList.push(val);
                }
            } else {
                state.currentMenu = null
            }
        },
        closeTag(state, val) {
            const result = state.tabsList.findIndex(item => item.title === val.title);
            state.tabsList.splice(result, 1);
        }
    },

    actions: {

    }
}

export default tab;